﻿import QtQuick 2.0

/**
 * 临时弹出对话框，类似安卓的
 */
Rectangle {
    id: rootToast
    radius: height*0.2
    color: "#474747"

    signal backSignal();
    // 如果公共控件则需将图片放在系统目录
//    source: "qrc:/images/ic_toast.png"
    anchors.horizontalCenter: parent.horizontalCenter
    height: content.paintedHeight+m_lineValue*0.4
    visible: false

    onVisibleChanged: {
        if(content.paintedWidth>=m_root_id.width*0.8)
        {
            rootToast.width = m_root_id.width*0.8+m_lineValue*0.2
            content.wrapMode = Text.WrapAnywhere
        }
        else{
            rootToast.width = content.paintedWidth+m_lineValue*0.2
        }
    }

    AText {
        id: content
        anchors.centerIn: parent
        anchors.fill: parent
        color: "#ffffff"
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        wrapMode: Text.NoWrap
        font.pointSize: 14
    }

    Timer {
        id: closeTimerId
        interval: 3000
        repeat: false
        running: false
        onTriggered: {
           content.text = ""
           rootToast.visible = false;
            if (true)
                backSignal()
        }
    }


    // 设置并显示提示消息
    function setMessage(text) {
        content.wrapMode = Text.NoWrap
        content.text = text
        rootToast.visible = false;
        rootToast.visible = true;
        closeTimerId.start()
    }
}
